var bsurl = require('../../../utils/baseUrl.js');
var netUtils = require('../../../utils/netUtils.js');
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    count: [0, 0, 0, 0],
    hidden:true,
    shopname:"",
    isOpen:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    app.editTabBar(app.globalData.tabBar1);
    var that = this;
    var isOpen="";
    if (app.globalData.userInfo.shopname){isOpen = "(已开通)"};
    this.setData({ name: app.globalData.userInfo.name1,isOpen:isOpen });
    for (var i = 0; i < 4; i++) {
      (function (arg) {
        netUtils.sendRequest("order/queryOrderCountByState.do", { state: arg }, (data) => {
          that.data.count[arg] = data.body;
          that.setData({ count: that.data.count });
        })
      })(i);
    }
  },
  //点击开通栏
  open:function(){
    if (this.data.isOpen) {
      return;
    }
    this.setData({hidden:false});
  },
  //弹框取消按钮
  cancel:function(){
    this.setData({ hidden: true, shopname:""});
  },
  //弹框开通按钮
  confirm:function(){ 
    console.log(this.data.shopname)
    if(!this.data.shopname){
      wx.showModal({
        title: '提示',
        content: '商店名不能为空',
      });
      return;
    }
    this.setData({ hidden: true });
    var body = app.globalData.userInfo;
    body.shopname = this.data.shopname;
    body.identity = 2;
    netUtils.sendRequest("user/modify.do",body,(data)=>{
      this.setData({isOpen:"(已开通)"})
      wx.showToast({
        title: '开通成功',
        icon:'success',
        duration:1500
      });
    });
  },
  //弹框输入框
  input:function(e){
    this.setData({shopname:e.detail.value});
  },
  //注销按钮
  quit:function(){
    wx.redirectTo({
      url: '/pages/login/login',
    })
  }
})